﻿namespace C12_Ex02_Shaked_032675316_Itay_032511057
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Net;
    using System.IO;
    using FacebookWrapper;
    using FacebookWrapper.ObjectModel;

    public class FacebookImageMapperToGalleryDisplayAdapter : IGalleryDisplayImageContainer
    {
        private FacebookImageMapper m_ImageMapper;
        private User m_User;

        public FacebookImageMapperToGalleryDisplayAdapter(FacebookImageMapper i_ImageMapper, User i_User)
        {
            m_ImageMapper = i_ImageMapper;
            m_User = i_User;
        }

        public List<Image> GetImageList()
        {
            return GetImagesList(m_User);
        }

        private List<Image> GetImagesList(User i_User)
        {
            List<Image> images = new List<Image>();

            List<string> newPictures = m_ImageMapper.GetNewPicturesList(i_User);

            if (newPictures != null)
            {
                foreach (string url in newPictures)
                {
                    WebRequest req = WebRequest.Create(url);
                    WebResponse response = req.GetResponse();
                    Stream stream = response.GetResponseStream();
                    images.Add(Image.FromStream(stream));
                }
            }

            return images;
        }
    }
}
